const tokens = {
  admin: {
    token: "5846e19b-960e-4c20-b79a-c64a7c91984d"
  },
  editor: {
    token: "editor-token"
  }
};

const users = {
  "5846e19b-960e-4c20-b79a-c64a7c91984d": {
    permissions: ["*:*:*"],
    roles: ["admin"],
    user: {
      searchValue: null,
      createBy: "admin",
      createTime: "2020-11-20 19:29:42",
      updateBy: null,
      updateTime: null,
      remark: "管理员",
      params: {},
      userId: 1,
      deptId: 103,
      userName: "admin",
      nickName: "若依",
      email: "ry@163.com",
      phonenumber: "15888888888",
      sex: "1",
      avatar: "",
      salt: null,
      status: "0",
      delFlag: "0",
      loginIp: "127.0.0.1",
      loginDate: "2020-11-20T19:29:42.000+0800",
      dept: {
        searchValue: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        params: {},
        deptId: 103,
        parentId: 101,
        ancestors: null,
        deptName: "研发部门",
        orderNum: "1",
        leader: "若依",
        phone: null,
        email: null,
        status: "0",
        delFlag: null,
        parentName: null,
        children: []
      },
      roles: [
        {
          searchValue: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          params: {},
          roleId: 1,
          roleName: "超级管理员",
          roleKey: "admin",
          roleSort: "1",
          dataScope: "1",
          menuCheckStrictly: false,
          deptCheckStrictly: false,
          status: "0",
          delFlag: null,
          flag: false,
          menuIds: null,
          deptIds: null,
          admin: true
        }
      ],
      roleIds: null,
      postIds: null,
      admin: true
    }
  }
};

module.exports = [
  // user login
  {
    url: "/dev-api/user/login",
    type: "post",
    response: config => {
      const { username } = config.body;
      const token = tokens[username];
      // mock error
      if (!token) {
        return {
          code: 60204,
          message: "Account and password are incorrect."
        };
      }

      return {
        code: 200,
        data: token
      };
    }
  },

  // get user info
  {
    url: "/dev-api/user/info",
    type: "get",
    response: () => {
      const token = "5846e19b-960e-4c20-b79a-c64a7c91984d";
      localStorage.setItem("TOKEN", "5846e19b-960e-4c20-b79a-c64a7c91984d");
      const info = users[token];
      // mock error
      if (!info) {
        return {
          code: 50008,
          message: "Login failed, unable to get user details."
        };
      }

      return {
        msg: "操作成功",
        code: 200,
        data: info
      };
    }
  },

  // user logout
  {
    url: "/dev-api/user/logout",
    type: "post",
    response: _ => {
      return {
        code: 200,
        data: "success"
      };
    }
  },
  {
    url: "/dev-api/getRouters",
    type: "get",
    response: _ => {
      return {
        msg: "操作成功",
        code: 200,
        data: [
          {
            name: "System",
            path: "/system",
            hidden: false,
            redirect: "noRedirect",
            component: "Layout",
            alwaysShow: true,
            meta: { title: "系统管理", icon: "system", noCache: false },
            children: [
              {
                name: "User",
                path: "user",
                hidden: false,
                component: "system/user/index",
                meta: { title: "用户管理", icon: "user", noCache: false }
              },
              {
                name: "Role",
                path: "role",
                hidden: false,
                component: "system/role/index",
                meta: { title: "角色管理", icon: "peoples", noCache: false }
              },
              {
                name: "Menu",
                path: "menu",
                hidden: false,
                component: "system/menu/index",
                meta: { title: "菜单管理", icon: "tree-table", noCache: false }
              },
              {
                name: "Dept",
                path: "dept",
                hidden: false,
                component: "system/dept/index",
                meta: { title: "部门管理", icon: "tree", noCache: false }
              }
            ]
          },
          {
            name: "Contract",
            path: "/contract",
            hidden: false,
            redirect: "noRedirect",
            component: "Layout",
            alwaysShow: true,
            meta: { title: "合同管理", icon: "excel", noCache: false },
            children: [
              {
                name: "Upstream",
                path: "upstream",
                hidden: false,
                component: "contract/upstream",
                meta: { title: "上游合同", icon: "education", noCache: false }
              },
              {
                name: "Supplier",
                path: "supplier",
                hidden: false,
                component: "contract/supplier",
                meta: {
                  title: "供货商采购合同",
                  icon: "peoples",
                  noCache: false
                }
              },
              {
                name: "Material",
                path: "material",
                hidden: false,
                component: "contract/material",
                meta: {
                  title: "物资进场计划",
                  icon: "list",
                  noCache: false
                }
              }
            ]
          },
          {
            name: "Supply",
            path: "/supply",
            redirect: "/supply/supplyindex",
            component: "Layout",
            meta: { title: "供货单管理", icon: "skill", noCache: false },
            children: [
              {
                name: "SupplyIndex",
                path: "supplyindex",
                hidden: false,
                component: "supply/index",
                meta: { title: "供货单管理", icon: "skill", noCache: false }
              }
            ]
          },
          {
            name: "Shiporder",
            path: "/shiporder",
            hidden: false,
            redirect: "noRedirect",
            component: "Layout",
            alwaysShow: true,
            meta: { title: "发货单管理", icon: "log", noCache: false },
            children: [
              {
                name: "shiporderIndex",
                path: "shiporderindex",
                hidden: false,
                component: "shiporder/index",
                meta: { title: "发货单管理", icon: "dict", noCache: false }
              },
              {
                name: "Check",
                path: "check",
                hidden: false,
                component: "shiporder/check",
                meta: {
                  title: "现场验收",
                  icon: "job",
                  noCache: false
                }
              }
            ]
          }
        ]
      };
    }
  }
];
